<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="督导姓名" prop="supName">
        <el-input
          v-model="queryParams.supName"
          placeholder="请输入督导姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="课程类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择课程类型" clearable size="small">
          <el-option
            v-for="dict in dict.type.supms_tpi_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="学年" prop="schoolYear">
        <el-input
          v-model="queryParams.schoolYear"
          placeholder="输入学年格式如：2020-2021"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学期" prop="schoolSemester">
        <el-select v-model="queryParams.schoolSemester" placeholder="请选择学期" @keyup.enter.native="handleQuery" clearable size="small">
          <el-option label="第1学期" value="第1学期"></el-option>
          <el-option label="第2学期" value="第2学期"></el-option>
          <el-option label="第3学期" value="第3学期"></el-option>
          <el-option label="第4学期" value="第4学期"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="课程名称" prop="courseName">
        <el-input
          v-model="queryParams.courseName"
          placeholder="请输入课程名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="教师姓名" prop="tName">
        <el-input
          v-model="queryParams.tName"
          placeholder="请输入教师姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['course:teachPlanRecord:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['course:teachPlanRecord:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['course:teachPlanRecord:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['course:teachPlanRecord:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="teachPlanRecordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" width="60" align="center">
        <template slot-scope="scope">
          {{scope.$index + 1}}
        </template>
      </el-table-column>
      <el-table-column label="督导姓名" width="100" align="center" prop="supName" />
      <el-table-column label="课程类型" width="160" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.supms_tpi_type" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="学年" width="160" align="center" prop="schoolYear">
        <template slot-scope="scope">
          {{scope.row.schoolYear + "学年"}}
        </template>
      </el-table-column>
      <el-table-column label="学期" width="120" align="center" prop="schoolSemester" />
      <el-table-column label="课程名称" align="center" prop="courseName" />
      <el-table-column label="教师姓名" width="100" align="center" prop="tName" />
      <el-table-column label="授课班级" align="center" prop="teachClass" />
      <el-table-column label="教案评价" width="140" align="center" prop="teachPlanSituationFlag">
        <template slot-scope="scope">
          <div v-if="scope.row.teachPlanSituationFlag === '0'">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-circle-plus-outline"
              @click="toTeachPlanEval(scope.row)"
              >去评价</el-button
            >
          </div>
          <div v-else-if="scope.row.teachPlanSituationFlag === '1'">
            <el-tag type="success">已评价</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="openTeachPlanTable(scope.$index)"
            >查看检查表</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['course:teachPlanRecord:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['course:teachPlanRecord:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改教案检查对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-row :gutter="15">
        <el-form ref="form" :model="form" :rules="rules" label-width="100px">
          <el-col :span="12">
            <el-form-item label="课程类型" prop="type">
              <el-select v-model="form.type" placeholder="请选择课程类型">
                <el-option
                  v-for="dict in dict.type.supms_tpi_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="学年学期" prop="schoolSemester">
              <div style="margin-top: 15px;">
                <el-input placeholder="输入学年格式如：2021-2022" v-model="form.schoolYear" style="width: 450px" class="input-with-select">
                  <el-select v-model="form.schoolSemester" slot="prepend" style="width: 120px" placeholder="请选择学期">
                    <el-option label="第1学期" value="第1学期"></el-option>
                    <el-option label="第2学期" value="第2学期"></el-option>
                    <el-option label="第3学期" value="第3学期"></el-option>
                    <el-option label="第4学期" value="第4学期"></el-option>
                  </el-select>
                  <template slot="append">学年</template>
                </el-input>
              </div>
            </el-form-item>
          </el-col>
          
          <el-col :span="12">
            <el-form-item label="课程名称" prop="courseName">
              <el-input v-model="form.courseName" placeholder="请输入课程名称" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开课学院" prop="courseDep">
              <el-input v-model="form.courseDep" placeholder="请输入开课学院" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="教师姓名" prop="tName">
              <el-input v-model="form.tName" placeholder="请输入教师姓名" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="教师工号" prop="tNum">
              <span slot="label">
                    <el-tooltip content="可在职工管理中查询，建议先填写其他重要信息保存后再补充">
                    <i class="el-icon-info"></i>
                    </el-tooltip>
                    教师工号
                  </span>
              <el-input v-model="form.tNum" :maxlength="11" oninput ="value=value.replace(/[^0-9.]/g,'')" placeholder="建议输入教师工号" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属部门" prop="tDep">
              <el-input v-model="form.tDep" placeholder="请输入所属部门" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="授课班级" prop="teachClass">
              <el-input v-model="form.teachClass" placeholder="请输入专业年级班级" clearable />
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 查看查看检查表 -->
    <el-dialog :title="title" :visible.sync="openTable" width="1000px" append-to-body>
      <!-- 添加滚动条 -->
      <el-scrollbar style="height: 700px;">
        <el-descriptions class="margin-top" :model="teachPlanTable" title="重庆三峡学院课程教案检查记录表" :column="3" border>

          <template slot="extra">
            {{"填表日期：" + parseTime(teachPlanTable.createTime, '{y}-{m}-{d}')}}
          </template>

          <el-descriptions-item>
            <template slot="label">
              课程类型
            </template>
            <dict-tag :options="dict.type.supms_tpi_type" :value="teachPlanTable.type"/>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              教案检查人
            </template>
            {{teachPlanTable.supName}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              教师姓名
            </template>
            {{teachPlanTable.tName}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              教师所在部门
            </template>
            {{teachPlanTable.tDep}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              课程名称
            </template>
            {{teachPlanTable.courseName}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              开课学院
            </template>
            {{teachPlanTable.courseDep}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              学年学期
            </template>
            {{teachPlanTable.schoolYear + "学年" + teachPlanTable.schoolSemester}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              授课专业年级班级
            </template>
            {{teachPlanTable.teachClass}}
          </el-descriptions-item>
        </el-descriptions>
      

        <el-table :data="teachPlanTable.teachPlanItems" border style="width: 100%">
          <el-table-column label="序号" width="60" align="center">
            <template slot-scope="scope">
              {{scope.$index + 1}}
            </template>
          </el-table-column>

          <el-table-column prop="content" width="250" label="评价指标" />
          <el-table-column prop="option" label="评价结果选项" />
          <el-table-column prop="selectOption" label="评价结果" align="center" width="80" />
        </el-table>
      </el-scrollbar>
    </el-dialog>
  </div>
</template>

<script>
import { listTeachPlanRecord, getTeachPlanRecord, delTeachPlanRecord, addTeachPlanRecord, updateTeachPlanRecord, getTeachPlanTable } from "@/api/course/teachPlanRecord";

export default {
  name: "TeachPlanRecord",
  dicts: ['supms_tpi_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 教案检查表格数据
      teachPlanRecordList: [],
      // 查看教案检查表数据
      teachPlanTable: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 显示查看教案检查表模态框
      openTable: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        supName: null,
        type: null,
        schoolYear: null,
        schoolSemester: null,
        courseName: null,
        tName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        type: [
          { required: true, message: "请选择课程类型", trigger: "change" },
        ],
        schoolSemester: [
          { required: true, message: "请输入学年学期", trigger: "blur" },
        ],
        courseName: [
          { required: true, message: "请输入课程名称", trigger: "blur" },
        ],
        courseDep: [
          { required: true, message: "请输入开课学院", trigger: "blur" },
        ],
        tName: [
          { required: true, message: "请输入教师姓名", trigger: "blur" },
        ],
        tDep: [
          { required: true, message: "请输入教师所属部门", trigger: "blur" },
        ],
        teachClass: [
          { required: true, message: "请输入授课班级", trigger: "blur" },
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询教案检查列表 */
    getList() {
      this.loading = true;
      listTeachPlanRecord(this.queryParams).then(response => {
        this.teachPlanRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        supName: null,
        type: null,
        schoolYear: null,
        schoolSemester: null,
        courseName: null,
        courseDep: null,
        tName: null,
        tNum: null,
        tDep: null,
        teachClass: null,
        teachPlanSituationFlag: null,
        createBy: null,
        updateBy: null,
        delFlag: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加教案检查";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTeachPlanRecord(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改教案检查";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTeachPlanRecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTeachPlanRecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除教案检查编号为"' + ids + '"的数据项？').then(function() {
        return delTeachPlanRecord(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('course/teachPlanRecord/export', {
        ...this.queryParams
      }, `teachPlanRecord_${new Date().getTime()}.xlsx`)
    },
    /** 去评价按钮操作 */
    toTeachPlanEval(row) {
      const recordId = row.id
      const typeNum = row.type
      this.$router.push({ path: '/course/teachPlanEval/toTPEval', query: { recordId: recordId, typeNum: typeNum, pageNum: this.queryParams.pageNum } });
    },
    /** 查看教案检查记录表按钮操作 */
    openTeachPlanTable(index) {
      const no = index
      const list = this.teachPlanRecordList[no]
      getTeachPlanTable(list).then((res) => {
        this.teachPlanTable = res
        this.openTable = true;
        this.title = "查看教案检查记录表";
      })
    },
  }
};
</script>

<style scoped>
div /deep/ .el-scrollbar__wrap {
  overflow-x: hidden;
}
</style>
